package com.example.springai.repository;


import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class InMemoryChatHistoryRepository implements ChatHistoryRepository{

    // 存放c chatId 的 Map
    private final Map<String, List<String>> chatHistory = new HashMap<>();


    @Override
    public void save(String type, String chatId) {
        List<String> chatIds = chatHistory.computeIfAbsent(type, s -> new ArrayList<>());

        if(!chatIds.contains(chatId)){
            chatIds.add(chatId);
        }
    }

    @Override
    public void delete(String type, String chatId) {

    }

    @Override
    public List<String> getChatIds(String type) {
        return chatHistory.getOrDefault(type, List.of());
    }
}
